package com.sayimo.maker.mall.goods.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sayimo.framework.database.mybatis.AbstractMybatisBaseDao;
import com.sayimo.framework.exception.DaoException;
import com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao;
import com.sayimo.maker.mall.goods.vo.GoodsComment;




/**
 * @Project: schoolmallapi
 * @ClassName: GoodsCommentInterfaceDao
 * @Description: 商品评论Dao
 * @Author:	曹频辉
 * @Date:	日期：2015年12月28日  时间：下午6:03:34
 * @Version 1.0.0
 */
@Repository(value="goodsCommentInterfaceImplDao")
public class GoodsCommentInterfaceImplDao extends AbstractMybatisBaseDao<GoodsComment>implements GoodsCommentInterfaceDao{
	/**
	* @Title: getGoodsCommentListByGoodsId 
	* @Description: 查询商品评论列表
	* @param goodsId
	* @param recordNum
	* @throws DaoException
	* @return List
	 */
	@Override
	public List getGoodsCommentListByGoodsId(Integer goodsId, Integer recordNum)
			throws DaoException {
		Map map=new HashMap();
		map.put("goodsId", goodsId);
		map.put("recordNum",recordNum);
		return this.mybatisInterfaceBaseDao.queryObject("com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao.getGoodsCommentListByGoodsId", map);
	}
	
	
	
	/**
	* @Title: getGoodsCommentStatistics 
	* @Description: 商品评论统计
	* @param goodsId
	* @throws DaoException
	* @return Map
	 */
	@Override
	public Map getGoodsCommentStatistics(Integer goodsId) throws DaoException {
		return (Map)this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao.getGoodsCommentStatistics", goodsId);
	}
	
	
	/**
	* @Title: addGoodsCommentOrReply 
	* @Description: 添加商品评论或回复
	* @param goodsComment
	* @throws DaoException
	* @return Integer
	 */
	@Override
	public Integer addGoodsCommentOrReply(GoodsComment goodsComment)
			throws DaoException {
		if(goodsComment.getType()!=null){
			if(goodsComment.getType()==2){
				return this.mybatisInterfaceBaseDao.insert("com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao.addGoodsCommentReply",goodsComment);
			}else if(goodsComment.getType()==1){
				return this.mybatisInterfaceBaseDao.insert("com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao.addGoodsComment",goodsComment);
			}else{
				throw new DaoException("类型不正确");
			}
		}else{
			throw new DaoException("类型不能为空");
		}
		
	}


	/**
	* @Title: getGoodsCommentReplyById 
	* @Description: 根据ID查询商品追加评论
	* @param replyId
	* @param commentId
	* @throws DaoException
	* @return Map
	 */
	@Override
	public Map getGoodsCommentReplyById(Integer replyId,Integer commentId) throws DaoException {
		Map map=new HashMap();
		map.put("replyId", replyId);
		map.put("commentId", commentId);
		return (Map)this.mybatisInterfaceBaseDao.getObject("com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao.getGoodsCommentReplyById", map);
	}
	/**
	 * 
	* @Title: getPurchaseTimesByCustomerId 
	* @Description: 获得该用户对于该商品的购买次数
	* @param customerId
	* @param goodsId
	* @return
	* @throws DaoException
	* @return Integer
	* @throws
	 */
	@Override
	public Integer getPurchaseTimesByCustomerId(Integer customerId,
			Integer goodsId) throws DaoException {
		Map map=new HashMap();
		map.put("customerId", customerId);
		map.put("goodsId", goodsId);
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao.getPurchaseTimesByCustomerId",map);
	}



	@Override
	public Integer getCommentCount(Map<String,Object> goodsComment) throws DaoException {
		
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao.getCommentCount",goodsComment);
	}
	
	
	/** 
	  * @package com.sayimo.school.mall.module.goods.dao
	  * @author chenpy
	  * @Title:  
	  * @Description: 获取某订单下还没有评论的商品个数
	  * @param 
	  * @throws 
	  * @return Integer
	  * @date 2016年10月19日
	  */ 
	public Integer getNotCommentCntGoodsInOrder(GoodsComment goodsComment) throws DaoException{
		return this.mybatisInterfaceBaseDao.queryCount("com.sayimo.maker.mall.goods.dao.GoodsCommentInterfaceDao.getNotCommentCntGoodsInOrder",goodsComment);
	}
}
